package com.application.common;

import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.application.config.BaseConfig;
import com.application.core.EsbAssist;
import com.application.iface.IApplication;



public class BaseContext {
	public static ApplicationContext context = null;
	public static EsbAssist esbAssist = null;	
	static{
		context = new ClassPathXmlApplicationContext("application.Context.xml");
		BaseConfig.getInstance().LoadConfig();
	}
	
	public static void Start(){
		Map<String, IApplication> allServices = context.getBeansOfType(IApplication.class);
		
		if(EmptyChecker.notEmpty(allServices)){
			for (IApplication service : allServices.values()) {
				if(service.before()){
					esbAssist = context.getBean("com.application.core.EsbAssist",com.application.core.EsbAssist.class);
					esbAssist.doStart();					
				}				
				service.after();
				break;
			}				
		}else{
			esbAssist = context.getBean("com.application.core.EsbAssist",com.application.core.EsbAssist.class);
			esbAssist.doStart();			
		}		
	}
	
	public static void main( String[] args )
    {
		BaseLogger.writeInfoLog("==================================================================================================\n\n");
		BaseLogger.writeInfoLog("启动子系统服务...\n\n");		
        BaseContext.Start();
    }
}
